package com.itheima.mapper;


import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    /**
     * 根据id 删除员工
     *
     * @param id 员工id
     */
    @Delete("delete from emp where id = #{id}")
    public int deleteEmpById(Integer id);

    /**
     * 新增员工
     *
     * @param emp 员工对象
     */
    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time) " +
            "values (#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
    public void insertEmp(Emp emp);

    /**
     * 更新员工
     *
     * @param emp 员工对象
     */
    @Update("update emp set username=#{username}, name=#{name}, gender=#{gender}, image=#{image}, job=#{job}, entrydate=#{entrydate}, dept_id=#{deptId}, update_time=#{updateTime} " +
            "where id=#{id}")
    public void updateEmp(Emp emp);

    /**
     * 根据id查询员工
     *
     * @param id 员工id
     */
    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time from emp where id=#{id}")
    public Emp getEmpById(Integer id);

    /**
     * 条件查询员工
     * @param name     员工姓名
     * @param gender   员工性别
     */
    //方法一
/*
    @Select("select * from emp " +
            "where name like '%${name}%' " +
            "and gender = #{gender} " +
            "and entrydate between #{begin} and #{end} " +
            "order by update_time desc")
    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);
*/

    //方法二
    /*@Select("select * from emp " +
            "where name like concat('%',#{name},'%') " +
            "and gender = #{gender} " +
            "and entrydate between #{begin} and #{end} " +
            "order by update_time desc")*/

    //动态条件查询
    public List<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);

    //动态更新员工
    public void updateEmps(Emp emp);

    //批量删除员工
    public void deleteEmpsByIds(List<Integer> ids);

}


